(function($) {
    //斑马线
    $.fn.zebra = function(color1, color2) {
        $(this).each(function(x) {
            if(x % 2 == 0) {
                $(this).css('background-color', color1);
            }
            else {
                $(this).css('background-color', color2);
            }
        });
    };


    //鼠标hover效果
    $.fn.lighten = function(color1, color2) {
        var o_color, c_color, c_line;
        var d = this;
        $(this).each(function(x) {
            $(this).mouseover(function() {
                if(c_line == x)	return;
                var color = $(this).css('background-color');
                o_color = color;
                $(this).css({
                    'background':color1
                });
            }).mouseout(function() {
                if(c_line == x) return;
                $(this).css({
                    'background':o_color
                });
            }).click(function() {
                //				setW('click:'+c_color);
                if(c_line == x)	return;

                $(this).css('background-color', color2);
                $(d).eq(c_line).css('background-color', c_color);
                c_color = o_color;
                c_line = x;
            });
        });
    };


    //附上阴影透明背影
    $.fn.shadow = function(class_name, fun) {
        var height = screen.height;
        var width = $('body').width();
//        alert(width);
        $(this).before('<div style="z-index:1;-moz-opacity:0.5;filter:alpha(opacity=50);position:absolute;background:#000;width:'+width+'px;height:'+height+'px;" class="' +class_name+ '" onclick="'+fun+'$(this).next().hide();$(this).remove();">&nbsp;</div>');
        $(function() {
            $('.'+class_name).bgiframe();
        })
    }

    //容器定位
    $.fn.setpos = function(align) {
        switch(align) {
            case 'center':
                var left = (screen.width - this.width())/2;
                var top =  (screen.height - this.height())/4;
                //var top = (screen.height - this.height())/4+this.height()/2;
                //                alert(left);
                this.css({
                    'position':'absolute',
                    'left':left,
                    'top':top,
                    'z-index':'9999'
                });
                break;
            case 'right':
                this.css({
                    'position':'absolute',
                    'right':0
                });
                break;
        }
    }

    //拖拽
    $.fn.drag = function() {
        var _this = this;
        //		var left = (screen.width - _this.width())/2;
        //		var top = (screen.height - _this.height())/4+_this.height()/2;
        //		_this.css({'z-index':12,'position':'absolute', 'left':left, 'top':top});
        _this.css({
            'z-index':12,
            'position':'absolute'
        });
        var dragObject = null;  //拖拽对象
        var mouseOffset = {}; //对象位置
        //捕获鼠标X,Y坐标
        function mouseCoords(ev) {
            if(ev.pageX || ev.pageY) {
                return {
                    x:ev.pageX,
                    y:ev.pageY
                    };
            }
            return {
                x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
                y:ev.clientY + document.body.scrollTop  - document.body.clientTop
            };
        }

        //捕获鼠标位置
        function getMouseOffset(target, ev) {
            ev = ev || window.event;
            var docPos = getPosition(target);
            var mousePos  = mouseCoords(ev);
            return {
                x:mousePos.x - docPos.x,
                y:mousePos.y - docPos.y
            };
        }
		
        //捕获对象位置
        function getPosition(e) {
            var left = _this.offset().left;
            var top = _this.offset().top;
            return {
                x:left,
                y:top
            };
        }

        //鼠标移动
        document.onmousemove = function(ev) {
            ev = ev || window.event;
            var mousePos = mouseCoords(ev);
            //			_this.html('鼠标x坐标：' + (mousePos.x-mouseOffset.x)+ '鼠标y坐标：' + (mousePos.y-mouseOffset.y));
            _this.html('l：' + _this.offset().left+ 't：' + _this.offset().top);

            if(dragObject) {
                var l = mousePos.x - mouseOffset.x;
                var t = mousePos.y - mouseOffset.y;
                $(dragObject).css({
                    'left':l,
                    'top':t
                });
            }
            return false;
        };

        //按下鼠标
        _this.mousedown(function(ev) {
            dragObject  = this;
            mouseOffset = getMouseOffset(this, ev);
            return false;
        })

        //放开鼠标
        _this.mouseup(function() {

            dragObject = null;
        })
    }

})(jQuery)